// Problem: I - Interseting Sequences
// Idea: Straightforward Dynamic Programming.
// Language: C++
// Author: Ivan Vladimirov Ivanov (ivan.vladimirov.ivanov@gmail.com)

#include <cstdio>
#include <cstring>

using namespace std;

#define MAX 100005

void input(void);
void solve(void);

int n;
int A[MAX];
int P[MAX];
int K[MAX];
int F[MAX];

int main(void)
{
  int t;
  scanf("%d", &t);
  while(t--) {
    input();
    solve();
  }
  return 0;
}

void input(void)
{
  scanf("%d", &n);
  for(int i = 0; i < n; i++) scanf("%d", &A[i]);
}

void solve(void)
{
  memset(P, -1, sizeof(P));
  for(int i = n - 1; i >= 0; i--) {
    K[i] = P[A[i]];
    P[A[i]] = i;
  }

  F[n] = 0;
  for(int i = n - 1; i >= 0; i--) {
    F[i] = F[i + 1];
    int k = K[i];
    if(k != -1 && F[i] < 1 + F[k]) F[i] = 1 + F[k];
  }

  printf("%d\n", F[0]);
}

